home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / MAKESHAR < prev    next >
Encoding:
Text File  |  1991-10-25  |  1.9 KB  |  77 lines

  1. #!/bin/sh
  2. #
  3. # MAKESHAR.sh: Make a shar file for the tcsh sources
  4. #
  5. # $Id: MAKESHAR,v 3.0 1991/07/17 00:33:58 christos Exp $
  6.  
  7. AWK=/usr/bin/nawk    # Must be nawk or gawk cause of 2D arrays
  8. WC=/usr/ucb/wc        
  9. GREP=/usr/bin/egrep
  10. SORT=/usr/bin/sort
  11. SH=/bin/sh
  12. #SH=cat
  13.  
  14. if [ "x$1" = "x" ]
  15. then
  16.     echo "Usage: $0 <version> <files>"    1>&2
  17.     exit
  18. fi
  19. VERSION=$1
  20. shift
  21.  
  22. $WC "$@" | $GREP -v total | $SORT +2 | $AWK '                \
  23. BEGIN {                                    \
  24.     i = 0;                                \
  25.     seq = 1;                                \
  26.     size = 0;                                \
  27.     name = 1;                                \
  28.     used = 2;                                \
  29.     tty = "/dev/tty";                            \
  30.     maxsize = 45000;                            \
  31.     dirs = "tcsh-'$VERSION' tcsh-'$VERSION'/config";            \
  32. };                                    \
  33. {                                    \
  34.     a[i, size] = $3;                            \
  35.     a[i, name] = $4;                            \
  36.     a[i, used] = 0;                            \
  37.     i++;                                \
  38. };                                    \
  39. END {                                    \
  40.     for (maxi = i--; i >= 0; i--) {                    \
  41.     idx = 0;                            \
  42.     if (a[i, used] == 0) {                        \
  43.         if (a[i, size] > maxsize)                     \
  44.         printf("Warning: File %s is %d > %d\n",            \
  45.                a[i, name], a[i, size], maxsize) > tty;        \
  46.         s = a[i, size];                        \
  47.         a[i, used] = 1;                        \
  48.         kit[seq, idx++] = i;                     \
  49.         j = 0;                            \
  50.         while (j < maxi) {                        \
  51.         # Find the greatest file we can add            \
  52.         j = maxi;                        \
  53.         for (k = 0; k < maxi; k++)                \
  54.             if (a[k, used] == 0 && a[k, size] + s < maxsize)    \
  55.             j = k;                        \
  56.         if (j < maxi) {                        \
  57.             s += a[j, size];                    \
  58.             a[j, used] = 1;                    \
  59.             kit[seq, idx++] = j;                 \
  60.         }                            \
  61.         }                                \
  62.         sizes[seq] = s;                        \
  63.         kit[seq++, idx] = -1;                     \
  64.     }                                \
  65.     }                                    \
  66.     for (i = 1; i < seq; i++) {                        \
  67.     printf("shar -n%d -e%d %s ", i, seq - 1, dirs);            \
  68.     printf("%2d of %2d: ", i, seq - 1) > tty;            \
  69.     for (j = 0; kit[i, j] != -1; j++) {                \
  70.         printf("%s ", a[kit[i, j], name]) > tty;            \
  71.         printf("%s ", a[kit[i, j], name]);                \
  72.     }                                \
  73.     printf("> tcsh-%d.shar;", i);                    \
  74.     printf("= %5d\n", sizes[i]) > tty;                \
  75.     }                                    \
  76. }' | $SH
  77.